/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: TestThread
 * Author:   AEO WUGUOZHI
 * Date:     2021/3/10 14:46
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bnuz;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author AEO WUGUOZHI
 * @create 2021/3/10
 * @since 1.0.0
 */
public class TestThread {
    public static volatile int sum = 0;

    public static synchronized void add(){
        sum++;
    }

    public static void main(String[] args) throws InterruptedException {
//        for(int i = 0;i < 1000;i++){
//            Thread thread = new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    int j = 0;
//                    while(j++ == 0){
//                        add();
//                    }
//                }
//            });
//            thread.start();
//        }
//        Thread.sleep(3000);
//        System.out.println(sum);
        //创建了5个核心线程
        ExecutorService service = Executors.newFixedThreadPool(5);
        //创建了100个任务。
        for(int i = 0;i < 100;i++){
            service.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("running.....");
                }
            });
        }
        Thread.sleep(5000);
        service.shutdown();
    }

}